package mark.tom.fiter.bean.config;

import androidx.annotation.IntDef;
import androidx.annotation.NonNull;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

import mark.tom.fiter.AbstractDTOConverter;

public class RequestConfig {

    // 是否上传文件表单
    private final boolean requestFileBody;
    // 请求是否是Form表单
    private final boolean requestFormBody;
    // 需要解析成的类
    private final Class<?> clazz;
    // 网络传输实体类转换器
    private final AbstractDTOConverter<?, ?> dtoConverter;
    // response类型
    @ResponseTypeEnums
    private final int responseType;

    private RequestConfig(Builder mBuilder) {
        requestFileBody = mBuilder.requestFileBody;
        requestFormBody = mBuilder.requestFormBody;
        clazz = mBuilder.clazz;
        dtoConverter = mBuilder.dtoConverter;
        responseType = mBuilder.responseType;
    }

    public boolean isRequestFileBody() {
        return requestFileBody;
    }

    public boolean isRequestFormBody() {
        return requestFormBody;
    }

    public Class<?> getClazz() {
        return clazz;
    }

    public AbstractDTOConverter<?, ?> getDtoConverter() {
        return dtoConverter;
    }

    @ResponseTypeEnums
    public int getResponseType() {
        return responseType;
    }

    public static final class Builder {
        // 是否上传文件表单
        boolean requestFileBody = false;
        // 请求是否是Form表单
        boolean requestFormBody = false;
        // 需要解析成的类
        Class<?> clazz;
        // 网络传输实体类转换器
        AbstractDTOConverter<?, ?> dtoConverter;
        // response类型
        @ResponseTypeEnums
        int responseType = RESPONSE_STRING;

        public Builder() {
        }

        public RequestConfig.Builder clz(@NonNull Class<?> val) {
            clazz = val;
            return this;
        }

        public RequestConfig.Builder converter(@NonNull AbstractDTOConverter<?, ?> val) {
            dtoConverter = val;
            return this;
        }

        public RequestConfig.Builder resType(@ResponseTypeEnums int val) {
            responseType = val;
            return this;
        }

        public RequestConfig.Builder formBody(boolean val) {
            requestFormBody = val;
            return this;
        }

        public RequestConfig.Builder fileBody(boolean val) {
            requestFileBody = val;
            return this;
        }

        public RequestConfig build() {
            return new RequestConfig(this);
        }
    }

    public static final int RESPONSE_STRING = 1;
    public static final int RESPONSE_BYTE = 2;

    @IntDef({
            RESPONSE_STRING,
            RESPONSE_BYTE
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface ResponseTypeEnums {
    }
}
